<template>
    <!-- 新增弹出框 -->
    <el-dialog title="新增"  :visible="Visible" :modal="true" width="30%" :show-close="true" 
               :destroy-on-close="true"
               :before-close="handleDialogClose"
               :close-on-click-modal="false">
        <el-form ref="rulesForm" :model="data"  :rules="rules" label-width="80px">
            <el-form-item label="站点名称" prop="site_name">
                <el-input v-model="data.site_name"></el-input>
            </el-form-item>
            <el-form-item label="域名/ip" prop="site_domain">
                <el-input v-model="data.site_domain"></el-input>
            </el-form-item>
            <el-form-item label="站点路径" prop="site_path">
                <el-input v-model="data.site_path"></el-input>
            </el-form-item>
            <el-form-item label="模板路径" prop="site_template">
                <el-input v-model="data.site_template"></el-input>
            </el-form-item>
            <el-form-item label="录入时间">
                <el-date-picker type="date" placeholder="选择日期" v-model="data.site_time" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
            </el-form-item>
            <el-form-item label="备注" prop="site_remarks">
                <el-input v-model="data.site_remarks"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <input type="radio" id="qiy" value="1" style="margin-left:20px" v-model="data.site_state">
                <label for="qiy">启用</label>
                <input type="radio" id="jiny" value="0" style="margin-left:50px" v-model="data.site_state">
                <label for="jiny">禁用</label>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
                <el-button @click="click_Close">关 闭</el-button>
                <el-button type="primary" @click="clicl_Save('rulesForm')">保 存</el-button>
            </span>
    </el-dialog>
</template>

<script>
    export default {
        name: "edit",
        inject:['refresh'],
        props: {
            Visible: {
                type:Boolean
            },
            data: {
                    site_pk: '',
                    site_name: '',
                    site_time: '',
                    site_domain: '',
                    site_path: '',
                    site_template: '',
                    site_remarks:'',
                    site_state: ''
            }
        },
        data(){
            return {
                url:'/cms/site/saveOrUpdate',

                //在return 后面
                rules: {
                    site_name: [
                        { required: true, message: "请输入角色名称", trigger: "change" },
                        { min: 2, max: 30, message: "长度在 2 到 30 个字符", trigger: "blur" }
                    ]
                }
            }
        },
        methods:{
            //关闭窗口方法
            click_Close(){
                // this.Visible=false;
                this.refresh();
            },
            //保存数据方法
            clicl_Save(formName){
                this.$refs[formName].validate(valid => {
                    if (valid) {
                        console.log("success submit!!");
                        this.$post(this.url, this.data).then(res => {
                            this.$message({
                                type : res.code,
                                message: res.msg,
                            });
                            this.Visible=false;
                            //刷新列表页的数据
                            this.refresh();
                        })
                    }else{
                        console.log("error submit !");
                        return false;
                        /*   this.$message({
                               type :res.code,
                               message: res.msg,
                           });*/
                    }
                })
            },
            //右上角关闭事件
            handleDialogClose(){
                this.click_Close();
            }
        }
    }
</script>

<style scoped>

</style>